package com.wx.springboot.step1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wx.springboot.step1.mbg.mapper.BrandMapper;
import com.wx.springboot.step1.mbg.model.Brand;
import com.wx.springboot.step1.mbg.model.BrandExample;
import com.wx.springboot.step1.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public List<Brand> list() {
        BrandExample example = new BrandExample();
//        example.setOrderByClause(" product_count asc ");
//        BrandExample.Criteria criteria = example.createCriteria();
////        criteria.andNameEqualTo("小米");
//        criteria.andProductCountLessThan(100);
//        criteria.andSortEqualTo(200);

        PageHelper.startPage(1,3); // 接下来执行的一条sql语句，将执行分页查询
        List<Brand> list = brandMapper.selectByExample(example);
        PageInfo<Brand> info = new PageInfo<Brand>(list);
        log.info("total:{}",info.getTotal());
        log.info("pageNum:{}",info.getPageNum());
        log.info("PageSize:{}",info.getPageSize());
        log.info("Pages:{}",info.getPages());
        return list;
    }
}
